home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / bsd / net / if.h < prev    next >
Text File  |  1995-02-14  |  9KB  |  266 lines

  1. /*
  2.  * Copyright (c) 1982, 1986 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  *
  6.  *    Copyright (c) 1994 NeXT Computer, Inc.
  7.  *
  8.  *    @(#)if.h    7.3 (Berkeley) 6/27/88 plus MULTICAST 1.1
  9.  */
  10. #ifndef _IF_
  11. #define _IF_ 1
  12.  
  13. /*
  14.  * Structures defining a network interface, providing a packet
  15.  * transport mechanism (ala level 0 of the PUP protocols).
  16.  *
  17.  * Each interface accepts output datagrams of a specified maximum
  18.  * length, and provides higher level routines with input datagrams
  19.  * received from its medium.
  20.  *
  21.  * Output occurs when the routine if_output is called, with three parameters:
  22.  *    (*ifp->if_output)(ifp, m, dst)
  23.  * Here m is the mbuf chain to be sent and dst is the destination address.
  24.  * The output routine encapsulates the supplied datagram if necessary,
  25.  * and then transmits it on its medium.
  26.  *
  27.  * On input, each interface unwraps the data received by it, and either
  28.  * places it on the input queue of a internetwork datagram routine
  29.  * and posts the associated software interrupt, or passes the datagram to a raw
  30.  * packet input routine.
  31.  *
  32.  * Routines exist for locating interfaces by their addresses
  33.  * or for locating a interface on a certain network, as well as more general
  34.  * routing and gateway routines maintaining information used to locate
  35.  * interfaces.  These routines live in the files if.c and route.c
  36.  */
  37.  
  38. #if    NeXT
  39. #import <net/netbuf.h>
  40. #import <net/netif.h>
  41. #endif    NeXT
  42.  
  43. /*
  44.  * Structure defining a queue for a network interface.
  45.  *
  46.  * (Would like to call this struct ``if'', but C isn't PL/1.)
  47.  */
  48. struct ifnet {
  49.     char    *if_name;        /* name, e.g. ``en'' or ``lo'' */
  50. #if    NeXT
  51.     char    *if_type;        /* type of interface */
  52. #endif    NeXT
  53.     short    if_unit;        /* sub-unit for lower level driver */
  54.     short    if_mtu;            /* maximum transmission unit */
  55.     short    if_flags;        /* up/down, broadcast, etc. */
  56. #if    NeXT
  57. #else    NeXT
  58.     short    if_timer;        /* time 'til if_watchdog called */
  59. #endif    NeXT
  60.     int    if_metric;        /* routing metric (external only) */
  61. #if    NeXT
  62.     int    if_class;        /* class of interface */
  63. #endif    NeXT
  64.     struct    ifaddr *if_addrlist;    /* linked list of addresses per if */
  65.     struct    ifqueue {
  66.         struct    mbuf *ifq_head;
  67.         struct    mbuf *ifq_tail;
  68.         int    ifq_len;
  69.         int    ifq_maxlen;
  70.         int    ifq_drops;
  71.     } if_snd;            /* output queue */
  72. /* procedure handles */
  73.     int    (*if_init)();        /* init routine */
  74.     int    (*if_output)();        /* output routine */
  75. #if    NeXT
  76.     int    (*if_control)();    /* control routine */
  77.     int    (*if_input)();        /* input routine */
  78.     netbuf_t   (*if_getbuf)();    /* get buffer routine */
  79. #else    NeXT
  80.     int    (*if_ioctl)();        /* ioctl routine */
  81.     int    (*if_reset)();        /* bus reset routine */
  82.     int    (*if_watchdog)();    /* timer routine */
  83. #endif    NeXT
  84. /* generic interface statistics */
  85.     int    if_ipackets;        /* packets received on interface */
  86.     int    if_ierrors;        /* input errors on interface */
  87.     int    if_opackets;        /* packets sent on interface */
  88.     int    if_oerrors;        /* output errors on interface */
  89.     int    if_collisions;        /* collisions on csma interfaces */
  90. #if    NeXT
  91.     void    *if_private;        /* private to interface */
  92. #endif    NeXT
  93. /* end statistics */
  94.     struct    ifnet *if_next;
  95. };
  96.  
  97. #if    NeXT
  98. #define    IFF_UP            0x1        /* interface is up */
  99. #define    IFF_BROADCAST    0x2        /* broadcast address valid */
  100. #define    IFF_DEBUG        0x4        /* turn on debugging */
  101. #define    IFF_LOOPBACK    0x8        /* is a loopback net */
  102. #define    IFF_POINTTOPOINT 0x10        /* interface is point-to-point link */
  103. #define    IFF_POINTOPOINT    0x10        /* interface is point-to-point link */
  104. #define    IFF_NOTRAILERS    0x20        /* avoid use of trailers */
  105. #define    IFF_RUNNING        0x40        /* resources allocated */
  106. #define    IFF_NOARP        0x80        /* no address resolution protocol */
  107. #define    IFF_PROMISC        0x100        /* receive all packets */
  108. #define    IFF_ALLMULTI    0x200        /* receive all multicast packets */
  109. #define IFF_DIALUP        0x400        /* For ISDN */
  110. #define    IFF_MULTICAST    0x800        /* supports multicast */
  111. #else    NeXT
  112. #endif    NeXT
  113.  
  114. /*
  115.  * The IFF_MULTICAST flag indicates that the network can support the
  116.  * transmission and reception of higher-level (e.g., IP) multicast packets.
  117.  * It is independent of hardware support for multicasting; for example,
  118.  * point-to-point links or pure broadcast networks may well support
  119.  * higher-level multicasts.
  120.  */
  121. #if    NeXT
  122. /* flags set internally only: */
  123. #define    IFF_CANTCHANGE (IFF_BROADCAST|IFF_POINTTOPOINT| \
  124.     IFF_RUNNING|IFF_AUTOCONF|IFF_AUTODONE|IFF_MULTICAST)
  125. #else    NeXT
  126. /* flags set internally only: */
  127. #define    IFF_CANTCHANGE    \
  128.     (IFF_BROADCAST | IFF_POINTTOPOINT | IFF_RUNNING | IFF_MULTICAST)
  129. #endif    NeXT
  130.  
  131. /*
  132.  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
  133.  * input routines have queues of messages stored on ifqueue structures
  134.  * (defined above).  Entries are added to and deleted from these structures
  135.  * by these macros, which should be called with ipl raised to splimp().
  136.  */
  137. #define    IF_QFULL(ifq)        ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
  138. #define    IF_DROP(ifq)        ((ifq)->ifq_drops++)
  139. #define    IF_ENQUEUE(ifq, m) { \
  140.     (m)->m_act = 0; \
  141.     if ((ifq)->ifq_tail == 0) \
  142.         (ifq)->ifq_head = m; \
  143.     else \
  144.         (ifq)->ifq_tail->m_act = m; \
  145.     (ifq)->ifq_tail = m; \
  146.     (ifq)->ifq_len++; \
  147. }
  148. #define    IF_PREPEND(ifq, m) { \
  149.     (m)->m_act = (ifq)->ifq_head; \
  150.     if ((ifq)->ifq_tail == 0) \
  151.         (ifq)->ifq_tail = (m); \
  152.     (ifq)->ifq_head = (m); \
  153.     (ifq)->ifq_len++; \
  154. }
  155. /*
  156.  * Packets destined for level-1 protocol input routines
  157.  * have a pointer to the receiving interface prepended to the data.
  158.  * IF_DEQUEUEIF extracts and returns this pointer when dequeueing the packet.
  159.  * IF_ADJ should be used otherwise to adjust for its presence.
  160.  */
  161. #define    IF_ADJ(m) { \
  162.     (m)->m_off += sizeof(struct ifnet *); \
  163.     (m)->m_len -= sizeof(struct ifnet *); \
  164.     if ((m)->m_len == 0) { \
  165.         struct mbuf *n; \
  166.         MFREE((m), n); \
  167.         (m) = n; \
  168.     } \
  169. }
  170. #define    IF_DEQUEUEIF(ifq, m, ifp) { \
  171.     (m) = (ifq)->ifq_head; \
  172.     if (m) { \
  173.         if (((ifq)->ifq_head = (m)->m_act) == 0) \
  174.             (ifq)->ifq_tail = 0; \
  175.         (m)->m_act = 0; \
  176.         (ifq)->ifq_len--; \
  177.         (ifp) = *(mtod((m), struct ifnet **)); \
  178.         IF_ADJ(m); \
  179.     } \
  180. }
  181. #define    IF_DEQUEUE(ifq, m) { \
  182.     (m) = (ifq)->ifq_head; \
  183.     if (m) { \
  184.         if (((ifq)->ifq_head = (m)->m_act) == 0) \
  185.             (ifq)->ifq_tail = 0; \
  186.         (m)->m_act = 0; \
  187.         (ifq)->ifq_len--; \
  188.     } \
  189. }
  190.  
  191. #define    IFQ_MAXLEN    50
  192. #define    IFNET_SLOWHZ    1        /* granularity is 1 second */
  193.  
  194. /*
  195.  * The ifaddr structure contains information about one address
  196.  * of an interface.  They are maintained by the different address families,
  197.  * are allocated and attached when an address is set, and are linked
  198.  * together so all addresses for an interface can be located.
  199.  */
  200. struct ifaddr {
  201.     struct    sockaddr ifa_addr;    /* address of interface */
  202.     union {
  203.         struct    sockaddr ifu_broadaddr;
  204.         struct    sockaddr ifu_dstaddr;
  205.     } ifa_ifu;
  206. #define    ifa_broadaddr    ifa_ifu.ifu_broadaddr    /* broadcast address */
  207. #define    ifa_dstaddr    ifa_ifu.ifu_dstaddr    /* other end of p-to-p link */
  208.     struct    ifnet *ifa_ifp;        /* back-pointer to interface */
  209.     struct    ifaddr *ifa_next;    /* next address for interface */
  210. };
  211.  
  212. /*
  213.  * Interface request structure used for socket
  214.  * ioctl's.  All interface ioctl's must have parameter
  215.  * definitions which begin with ifr_name.  The
  216.  * remainder may be interface specific.
  217.  */
  218. struct    ifreq {
  219. #define    IFNAMSIZ    16
  220.     char    ifr_name[IFNAMSIZ];        /* if name, e.g. "en0" */
  221.     union {
  222.         struct    sockaddr ifru_addr;
  223.         struct    sockaddr ifru_dstaddr;
  224.         struct    sockaddr ifru_broadaddr;
  225.         short    ifru_flags;
  226.         short    ifru_mtu;
  227.         u_long    ifru_asyncmap;        /* For PPP */
  228.         int    ifru_metric;
  229.         caddr_t    ifru_data;
  230.     } ifr_ifru;
  231. #define    ifr_addr    ifr_ifru.ifru_addr    /* address */
  232. #define    ifr_dstaddr    ifr_ifru.ifru_dstaddr    /* other end of p-to-p link */
  233. #define    ifr_broadaddr    ifr_ifru.ifru_broadaddr    /* broadcast address */
  234. #define    ifr_flags    ifr_ifru.ifru_flags    /* flags */
  235. #define    ifr_mtu        ifr_ifru.ifru_mtu    /* mtu for PPP*/
  236. #define    ifr_asyncmap    ifr_ifru.ifru_asyncmap    /* async control char map */
  237. #define    ifr_metric    ifr_ifru.ifru_metric    /* metric */
  238. #define    ifr_data    ifr_ifru.ifru_data    /* for use by interface */
  239. };
  240.  
  241. /*
  242.  * Structure used in SIOCGIFCONF request.
  243.  * Used to retrieve interface configuration
  244.  * for machine (useful for programs which
  245.  * must know all networks accessible).
  246.  */
  247. struct    ifconf {
  248.     int    ifc_len;        /* size of associated buffer */
  249.     union {
  250.         caddr_t    ifcu_buf;
  251.         struct    ifreq *ifcu_req;
  252.     } ifc_ifcu;
  253. #define    ifc_buf    ifc_ifcu.ifcu_buf    /* buffer address */
  254. #define    ifc_req    ifc_ifcu.ifcu_req    /* array of structures returned */
  255. };
  256.  
  257. #import <net/if_arp.h>
  258. #ifdef KERNEL
  259. struct    ifqueue rawintrq;        /* raw packet input queue */
  260. struct    ifnet *ifnet;
  261. struct    ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet();
  262. struct    ifaddr *ifa_ifwithdstaddr();
  263. #endif KERNEL
  264.  
  265. #endif /* _IF_ */
  266.